﻿// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System.Collections.Generic;

using Nova.CodeDOM;

namespace Nova.UI
{
    /// <summary>
    /// The view model for a <see cref="CodeDOM.MultiEnumMemberDecl"/>.
    /// </summary>
    public class MultiEnumMemberDeclVM : EnumMemberDeclVM
    {
        #region /* STATICS */

        internal static new void AddViewModelMapping()
        {
            CreateViewModel.Add(typeof(MultiEnumMemberDecl),
                delegate(CodeObject codeObject, bool isDescription, Dictionary<CodeObject, CodeObjectVM> dictionary) { return new MultiEnumMemberDeclVM((MultiEnumMemberDecl)codeObject, dictionary); });
        }

        #endregion

        #region /* FIELDS */

        protected ChildListVM<EnumMemberDeclVM> _enumMemberDeclVMs;

        #endregion

        #region /* CONSTRUCTORS */

        /// <summary>
        /// Create a view model instance for the specified <see cref="CodeDOM.MultiEnumMemberDecl"/>.
        /// </summary>
        public MultiEnumMemberDeclVM(MultiEnumMemberDecl multiEnumMemberDecl, Dictionary<CodeObject, CodeObjectVM> dictionary)
            : base(multiEnumMemberDecl, dictionary)
        {
            _enumMemberDeclVMs = CreateListVM<EnumMemberDecl, EnumMemberDeclVM>(multiEnumMemberDecl.MemberDecls, dictionary);
        }

        #endregion

        #region /* PROPERTIES */

        /// <summary>
        /// The underlying <see cref="CodeDOM.MultiEnumMemberDecl"/> model.
        /// </summary>
        public MultiEnumMemberDecl MultiEnumMemberDecl
        {
            get { return (MultiEnumMemberDecl)CodeObject; }
        }

        /// <summary>
        /// The list of <see cref="EnumMemberDeclVM"/>s.
        /// </summary>
        public ChildListVM<EnumMemberDeclVM> MemberDecls
        {
            get { return _enumMemberDeclVMs; }
        }

        /// <summary>
        /// The number of <see cref="EnumMemberDeclVM"/>s.
        /// </summary>
        public int Count
        {
            get { return _enumMemberDeclVMs.Count; }
        }

        /// <summary>
        /// Get the <see cref="EnumMemberDeclVM"/> at the specified index.
        /// </summary>
        public EnumMemberDeclVM this[int index]
        {
            get { return _enumMemberDeclVMs[index]; }
        }

        #endregion

        #region /* METHODS */

        #endregion

        #region /* RENDERING */

        public override void Render(CodeRenderer renderer, RenderFlags flags)
        {
            renderer.RenderList(_enumMemberDeclVMs, flags | RenderFlags.NoIncreaseIndent, this);
        }

        public override void RenderType(CodeRenderer renderer, RenderFlags flags)
        { }

        public override void RenderVisible(CodeRenderer renderer, RenderFlags flags)
        {
            base.RenderVisible(renderer, flags);
            renderer.RenderVisibleList(_enumMemberDeclVMs, flags);
        }

        public override void UnRender()
        {
            ChildListHelpers.UnRender(_enumMemberDeclVMs);
            base.UnRender();
        }

        #endregion
    }
}
